package com.ihr360.payroll.model.dto.salary.superclass;


import com.ihr360.commons.model.IIntIndexableEntity;
import com.ihr360.commons.model.INamedEntity;
import com.ihr360.commons.model.entity.NumberId;
import com.ihr360.commons.model.type.BenefitsPayer;
import com.ihr360.commons.model.type.NumOperation;
import com.ihr360.payroll.model.base.ISalaryField;
import com.ihr360.payroll.model.dto.salary.basecode.SalaryFieldType;
import com.ihr360.payroll.model.dto.salary.basecode.SalaryTaxType;

import javax.persistence.Column;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;

@MappedSuperclass
public abstract class AbstractSalaryField<V extends AbstractSalaryFieldValue<V>>
		extends NumberId<Long> implements ISalaryField<V>, IIntIndexableEntity, INamedEntity {
	private static final long serialVersionUID = 6164360231148108186L;

	/** 名称 */
	@Column(nullable = false, length = 50)
	protected String name;

	/** 序号 */
	protected int indexno = 1;

	/** 薪资项目类别 */
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(nullable = false)
	protected SalaryFieldType type;

	/** 员工收入计算规则 */
	@Enumerated(EnumType.STRING)
	protected NumOperation personalSalaryNumOp;

	/** 公司成本计算规则 */
	@Enumerated(EnumType.STRING)
	protected NumOperation companyCostNumOp;

	/** 缴税类型 */
	@ManyToOne(fetch = FetchType.EAGER)
	protected SalaryTaxType taxType;

	/** 承担方 */
	@Enumerated(EnumType.STRING)
	private BenefitsPayer payer;

	/** 实际承担方 */
	@Enumerated(EnumType.STRING)
	private BenefitsPayer actualPayer;

	/**
	 * 是否是合并计税项目,只有系统能控制
	 * @return
	 */
	@Column(columnDefinition = "bit(1) default 0")
	private boolean taxMergeField;

	/**
	 * 是否可导入
	 */
	@Column(columnDefinition = "bit(1) default 1")
	private boolean importField = true;

	/**
	 * 是否可导出
	 */
	@Column(columnDefinition = "bit(1) default 1")
	private boolean exportField = true;

	@Override
	public String getName() {
		return name;
	}


	@Override
	public void setName(String name) {
		this.name = name;
	}

	public SalaryFieldType getType() {
		return type;
	}

	public void setType(SalaryFieldType type) {
		this.type = type;
	}

	@Override
	public boolean isPersonalSalary() {
		return null != getPersonalSalaryNumOp();
	}

	@Override
	public boolean isCompanyCost() {
		return null != getCompanyCostNumOp();
	}

	public NumOperation getPersonalSalaryNumOp() {
		return personalSalaryNumOp;
	}

	public void setPersonalSalaryNumOp(NumOperation personalSalaryNumOp) {
		this.personalSalaryNumOp = personalSalaryNumOp;
	}

	public NumOperation getCompanyCostNumOp() {
		return companyCostNumOp;
	}

	public void setCompanyCostNumOp(NumOperation companyCostNumOp) {
		this.companyCostNumOp = companyCostNumOp;
	}

	public SalaryTaxType getTaxType() {
		return taxType;
	}

	public void setTaxType(SalaryTaxType taxType) {
		this.taxType = taxType;
	}

	public BenefitsPayer getPayer() {
		return payer;
	}

	public void setPayer(BenefitsPayer payer) {
		this.payer = payer;
	}

	public BenefitsPayer getActualPayer() {
		return actualPayer;
	}

	public void setActualPayer(BenefitsPayer actualPayer) {
		this.actualPayer = actualPayer;
	}

	public abstract V getValueMeta();

	public abstract void setValueMeta(V valueMeta);

	public boolean isTaxMergeField() {
		return taxMergeField;
	}

	public void setTaxMergeField(boolean taxMergeField) {
		this.taxMergeField = taxMergeField;
	}

	public boolean isImportField() {
		return importField;
	}

	public void setImportField(boolean importField) {
		this.importField = importField;
	}

	public boolean isExportField() {
		return exportField;
	}

	public void setExportField(boolean exportField) {
		this.exportField = exportField;
	}

	@Override
	public int getIndexno() {
		return indexno;
	}
	@Override
	public void setIndexno(int indexno) {
		this.indexno = indexno;
	}

}
